package com.example.wechatdaka.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.wechatdaka.entity.Clazz;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.wechatdaka.entity.UserTeacher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lx
 * @since 2020-11-26
 */

public interface ClazzMapper extends BaseMapper<Clazz> {
    List<UserTeacher> selectTeacherList();
    @Select("select c.id,c.lxClazzName,c.lxTeacher,u.lxUsername as lxTeacherName,c.lxClazzPeopleNum\n" +
            "from lx_user u\n" +
            "right join lx_user_teacher t on t.lxUserId=u.id\n" +
            "right join lx_clazz c on c.lxTeacher=t.lxUserId")
    public List<Clazz> queryAllClazz();
    @Select("select c.id,c.lxClazzName,c.lxTeacher,u.lxUsername as lxTeacherName,c.lxClazzPeopleNum\n" +
            "from lx_user u\n" +
            "right join lx_user_teacher t on t.lxUserId=u.id\n" +
            "right join lx_clazz c on c.lxTeacher=t.lxUserId")
    public IPage<Clazz> queryAllClazzPage(Page page);
    @Update("update lx_clazz set lxClazzPeopleNum = #{size} where id=#{id}")
    public int updatePeopleNum(String id,int size);
    @Select("select c.id,c.lxClazzName,c.lxTeacher,u.lxUsername as lxTeacherName,c.lxClazzPeopleNum\n" +
            "from lx_user u\n" +
            "right join lx_user_teacher t on t.lxUserId=u.id\n" +
            "right join lx_clazz c on c.lxTeacher=t.lxUserId\n" +
            "where u.id=#{id}")
    public IPage<Clazz> queryClazzByTeacherPage(Page page,String id);
    @Select("select c.id,c.lxClazzName,c.lxTeacher,u.lxUsername as lxTeacherName,c.lxClazzPeopleNum\n" +
            "from lx_user u\n" +
            "right join lx_user_teacher t on t.lxUserId=u.id\n" +
            "right join lx_clazz c on c.lxTeacher=t.lxUserId\n" +
            "where c.lxClazzName like concat('%',#{keyword},'%')")
    public IPage<Clazz> queryClazzByKeywordPage(Page page,String keyword);

}
